package cn.openea.perpartner.meily.web.controller;

import cn.openea.perpartner.common.core.web.controller.BaseController;
import cn.openea.perpartner.common.core.web.domain.AjaxResult;
import cn.openea.perpartner.common.core.web.page.TableDataInfo;
import cn.openea.perpartner.meily.web.entity.BlackList;
import cn.openea.perpartner.meily.web.entity.vo.BlackListVo;
import cn.openea.perpartner.meily.web.service.IBlackListService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


/**
 * 黑名单
 *
 * @author ysk
 * @email zane_ysk@qq.com
 * @date 2023-03-28 16:50:14
 */
@Api(tags = "黑名单管理")
@RestController
@RequestMapping("/blacklist")
public class BlackListController extends BaseController {

    @Resource
    private IBlackListService blackListService;


    @ApiOperation(value = "获取黑名单列表")
    @GetMapping("/list")
    public TableDataInfo list(BlackListVo vo) {
        startPage();
        List<BlackList> list = blackListService.findListByVo(vo);
        return getDataTable(list);
    }

    @ApiOperation(value = "新增黑名单")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody @Valid BlackList blackList) {
        blackListService.add(blackList);
        return AjaxResult.success();
    }

    @ApiOperation(value = "移除黑名单")
    @PostMapping("/remove/{id}")
    public AjaxResult remove(@PathVariable String id) {
        blackListService.removeById(id);
        return AjaxResult.success();
    }

    @ApiOperation(value = "移出黑名单")
    @PostMapping("/removeByUserId")
    public AjaxResult removeByUserId(@RequestBody BlackList blackList) {
        return toAjax(blackListService.removeByUserId(blackList));
    }

}
